package com.funwell.server.constants;

import java.util.ArrayList;
import java.util.List;


/**
 * 用户类型枚举类 <p>
 * 
 * 系统级别的用户类型，与表对应，原则上不做新增，管理系统的角色不算在这里面
 * @author fulei
 */
public enum SysUserTypeEnum implements IEnum {
    SYS("SYS", "系统"), // 表示系统自动
    DOC("DOC", "医生"),
    PAT("PAT", "患者"),
    ADM("ADM", "管理员");
    
    private String key;
    private String value;
    
    private SysUserTypeEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }
    
    public String toString() {
        return this.key;
    }
    
    public static SysUserTypeEnum getByKey(String key) {
        SysUserTypeEnum[] es = SysUserTypeEnum.values();
        for (int i = 0; i < es.length; i++) {
            if (es[i].getKey().equals(key))
                return es[i];
        }
        return null;
    }
    
    public static String[] toArray(List<SysUserTypeEnum> enumList) {
        if (null == enumList || enumList.isEmpty())
            return null;
        String[] status = new String[enumList.size()];
        for (int i = 0; i < enumList.size(); i++) {
            status[i] = enumList.get(i).getKey();
        }
        return status;
    }
    
    public static List<SysUserTypeEnum> fromArray(String[] typeNameList) {
        List<SysUserTypeEnum> enumList = new ArrayList<SysUserTypeEnum>();
        SysUserTypeEnum e = null;
        for (int i = 0; i < typeNameList.length; i++) {
            e = getByKey(typeNameList[i]);
            if (null == e) continue;
            enumList.add(e);
            e = null;
        }
        return enumList;
    }
}
